﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;

public partial class Index : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["username"] == null)
        {
            Response.Redirect("Login.aspx");
        }
        lab_Time.Text = "当前系统时间：" + DateTime.Now;
        lab_User.Text = "用户：" + CMSUser.Current.Name;
    }
    protected void btOK_Click(object sender, EventArgs e)
    {
        using (DataClassesDataContext dataContext = new DataClassesDataContext())
        {
            Users dUser = dataContext.Users.FirstOrDefault(o => o.ID == CMSUser.Current.ID && o.PassWord == tbPassword.Text.Trim());
            if (dUser != null)
            {
                if (tbPassword1.Text.Equals(tbPassword2.Text))
                {
                    dUser.PassWord = tbPassword2.Text;
                    dataContext.SubmitChanges();
                    Frame.Global.GlobalFunctions.Alert("密码修改成功!");
                }
                else
                {
                    Frame.Global.GlobalFunctions.Alert("新密码两次输入不一致!");
                }
            }
            else
            {
                Frame.Global.GlobalFunctions.Alert("旧密码错误!");
            }
        }
    }
}